//
//  YearOnYearAndLinkRelativeView.m
//  cocoapodText
//
//  Created by apple on 16/9/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ShiPei.h"
#import <Foundation/Foundation.h>
#import "YearOnYearAndLinkRelativeView.h"

@interface YearOnYearAndLinkRelativeView()
@end

@implementation YearOnYearAndLinkRelativeView

/**
 *  初始化视图属性
 *
 *  @param frame 视图frame
 *
 *  @return self
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //定制View
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES; //设置为NO后，不再响应touch方法
        self.multipleTouchEnabled = YES;
        //控制子视图不能超出父视图的范围
        self.clipsToBounds = YES;
        //添加子视图
        [self subView];
    }
    return self;
}

//子视图懒加载
-(void)subView{
    
    //类型描述
    UILabel *CardTypeLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:5 :0 :70 :25]];
    [CardTypeLabel setUserInteractionEnabled:YES];
    [CardTypeLabel setText:@""];
    [CardTypeLabel setTextColor:FUIColorFromRGB(0x333333)];
    [CardTypeLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:22]]];
    [CardTypeLabel setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:CardTypeLabel];
    self.CardTypeLabel=CardTypeLabel;
    //概览信息背景
    UIView *GYCardNumberAndUnitBGView=[[UIView alloc]initWithFrame:[ShiPei CGRectMakeScale:75 :0 :250 :25]];
    [self addSubview:GYCardNumberAndUnitBGView];
    //概览
    UILabel *GYCardNumberLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [GYCardNumberLabel setTextColor:FUIColorFromRGB(0xff3a00)];
    [GYCardNumberLabel setText:@""];
    [GYCardNumberLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:24]]];
    [GYCardNumberAndUnitBGView addSubview:GYCardNumberLabel];
    self.CardNumberLabel=GYCardNumberLabel;
    
    //概览单位
    UILabel *GYCardUnitLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [GYCardUnitLabel setTextColor:FUIColorFromRGB(0x333333)];
    [GYCardUnitLabel setText:@""];
    [GYCardUnitLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:22]]];
    [GYCardNumberAndUnitBGView addSubview:GYCardUnitLabel];
    self.CardUnitLabel=GYCardUnitLabel;
    
    UIImageView *imageView1=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:19 :29 :17 :16]];
    [self addSubview:imageView1];
    [imageView1 setImage:[UIImage imageNamed:@"huanbi_up.png"]];
    
    UILabel *YearOnYearLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:50 :25 :117.5 :25]];
    [self addSubview:YearOnYearLabel];
    [YearOnYearLabel setText:@""];
    [YearOnYearLabel setTextColor:FUIColorFromRGB(0x333333)];
    [YearOnYearLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:23]]];
    self.YearOnYearLabel=YearOnYearLabel;
    
    _tongbiImageView=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:171.5 :29 :17 :16]];
    [self addSubview:_tongbiImageView];
    [_tongbiImageView setImage:[UIImage imageNamed:@"tongbi_up.png"]];
    
    UILabel *LinkRelativeLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:202.5 :25 :117.5 :25]];
    [self addSubview:LinkRelativeLabel];
    [LinkRelativeLabel setText:@""];
    [LinkRelativeLabel setTextColor:FUIColorFromRGB(0x333333)];
    [LinkRelativeLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:23]]];
    self.LinkRelativeLabel=LinkRelativeLabel;
    
    UIImageView *fengexian=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:15 :49 :300 :1]];
    [fengexian setBackgroundColor:FUIColorFromRGB(0xf4f4f4)];
    [self addSubview:fengexian];
    self.fengexian=fengexian;
}

-(void)setHiddenFenGeXian:(BOOL)hidden{
    [self.fengexian setHidden:hidden];
}

-(void)setCardType:(NSString *)type{
    [self.CardTypeLabel setText:type];
}
-(void)setNumber:(NSString *)number{
    number=[CommonTool keepDecimal:number];
    [self.CardNumberLabel setText:number];
    [self.CardNumberLabel sizeToFit];
    CGFloat CardNumberW=self.CardNumberLabel.frame.size.width;
    CGFloat CardNumberH=self.CardNumberLabel.frame.size.height;
    CGFloat CardUnitH=self.CardUnitLabel.frame.size.height;
    CGRect NumberFrame=[ShiPei CGRectMakeScale:0 :(25-CardNumberH)/2:CardNumberW :CardNumberH];
    [self.CardNumberLabel setFrame:NumberFrame];
    
    CGRect UnitFrame=self.CardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(25-CardUnitH)/2;
    [self.CardUnitLabel setFrame:UnitFrame];
}

-(void)setUnit:(NSString *)unit{
    [self.CardUnitLabel setText:unit];
    [self.CardUnitLabel sizeToFit];
    CGFloat CardNumberW=self.CardNumberLabel.frame.size.width;
    CGFloat CardUnitH=self.CardUnitLabel.frame.size.height;
    
    CGRect UnitFrame=self.CardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(25-CardUnitH)/2;
    [self.CardUnitLabel setFrame:UnitFrame];
}

-(void)setYearOnYear:(NSString *)yearOnYear status:(NSString *)status{
    [self.YearOnYearLabel setText:[@"环比：" stringByAppendingString:yearOnYear]];
}

-(void)setLinkRelative:(NSString *)linkRelative status:(NSString *)status{
    if ([status isEqualToString:@"1"]) {
        [_tongbiImageView setImage:[UIImage imageNamed:@"tongbi_up.png"]];
    }else{
        [_tongbiImageView setImage:[UIImage imageNamed:@"tongbi_down.png"]];
    }
    [self.LinkRelativeLabel setText:[@"同比：" stringByAppendingString:linkRelative]];
}

//登录
-(void)setData{
    if([_delegate respondsToSelector:@selector(onSetData:)]){
        [_delegate onSetData:self];
    }
}

@end
